package net.guerlab.loadbalancer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author guer
 */
public class WeightList<T> extends ArrayList<TargetWrapper<T>> {

    public WeightList(List<TargetWrapper<T>> activeTargetList, Map<T, Integer> weightMap) {
        for (TargetWrapper<T> wrapper : activeTargetList) {
            int weight = weightMap.getOrDefault(wrapper.getTarget(), ILoadBalancer.MIN_WEIGHT);
            for (int i = 0; i < weight; i++) {
                add(wrapper);
            }
        }
    }
}
